package tenumn.energytech.registrys.recipe;

import com.google.gson.JsonObject;
import io.github.uicdb.liba.api.register.LazyRecipeSerializer;
import io.github.uicdb.liba.api.register.RecipeHolder;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import tenumn.energytech.registrys.RecipeRegistry;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class GrinderRecipe extends OneToTwoRecipe {


    @Nonnull
    @Override
    protected RecipeHolder<?> getRecipeHolder() {
        return RecipeRegistry.GRINDER;
    }

    public GrinderRecipe(Ingredient input, ItemStack outFirst, ItemStack outSecond, double secondChance) {
        super( input, outFirst, outSecond, secondChance);
    }
    public static final class Ser extends LazyRecipeSerializer<GrinderRecipe> {

        @Override
        public GrinderRecipe fromJson(ResourceLocation pRecipeId, JsonObject pSerializedRecipe) {
            var result= GSON.fromJson(pSerializedRecipe,GrinderRecipe.class);
            result.setId(pRecipeId);
            return result;
        }

        @Nonnull
        @Override
        public GrinderRecipe fromNetwork(ResourceLocation pRecipeId, FriendlyByteBuf pBuffer) {
            var result= GSON.fromJson(pBuffer.readUtf(),GrinderRecipe.class);
            result.setId(pRecipeId);
            return result;
        }

        @Override
        public void toNetwork(FriendlyByteBuf pBuffer, GrinderRecipe pRecipe) {
            pBuffer.writeUtf(GSON.toJson(pRecipe));
        }
    }

}
